


import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;

import db.DbUtils;
import db.Picture;

/**
 * Servlet implementation class for Servlet: Get16pic
 *
 */
 public class Get16pic extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
 
		protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			Session hbSession = DbUtils.startSession();
			String pageNumberStr = request.getParameter("pageNumber");
			long allPages=0;
			int pageNumber = 0;
			try {
				pageNumber = Integer.parseInt(pageNumberStr);
				List<Picture> pictures = DbUtils.get16Pictures(hbSession, pageNumber);
				allPages=DbUtils.getAllPicturesNum(hbSession);
				if(allPages%16!=0){
					allPages=(allPages/16)+1;
				}else{
					allPages=(allPages/16);
				}
				request.setAttribute("pictures", pictures);
				request.setAttribute("pageNumber", pageNumber);
				request.setAttribute("allPages", allPages);			
				
				request.getRequestDispatcher("Picture.jsp").forward(request, response);
			}catch (Exception e) {
				response.sendRedirect("Error.jsp");
			}
		}  	    
}